﻿using Kele.Activity.Core;
using Kele.Activity.Models;
using Kele.Activity.Models.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Kele.Activity.Web.Controllers.V1
{

    public partial class ActivityController : SiteApiController
    {
        [HttpGet("read")]
        public async Task<IActionResult> Read(int id)
        {
            var activity = await AppService.Activity.GetActivityAsync(id);
            if (activity == null) return ErrorResult($"没有找到活动,id={id}");
            var form = await AppService.Form.GetFormAsync(activity.FormId);
            return OkResult(new { form, activity });
        }

        [HttpGet("list")]
        public async Task<IActionResult> List([FromQuery] ActivityListInputDto dto)
        {
            var ret = await AppService.Activity.GetActivityListAsync(MerchantId, dto);
            return OkResult(ret);
        }

        [HttpPost("update")]
        public async Task<IActionResult> Update([FromBody] ActivityInputDto dto)
        {

            dto.MerchantId = MerchantId;
            var ret = await AppService.Activity.UpdateActivityAsync(MerchantId,dto);
            return OkResult(ret);
        }

        [HttpPost("create")]
        public async Task<IActionResult> Create([FromBody] ActivityInputDto dto)
        {
            dto.MerchantId = MerchantId;
            var ret = await AppService.Activity.CreateActivityAsync(MerchantId,dto);
            return OkResult(ret);
        }


        [HttpPost]
        [Route("status/update")]
        public async Task<IActionResult> UpdateActivityStatus(int id,int status)
        {
            var ret = await AppService.Activity.UpdateActivityStatusAsync(MerchantId, id,status);
            return OkResult(ret);
        }

        [HttpPost]
        [Route("delete")]
        public async Task<IActionResult> DeleteActivity(int activity_id)
        {
            var ret = await AppService.Activity.DeleteActivityAsync(MerchantId, activity_id);
            return OkResult(ret);
        }

        [HttpPost]
        [Route("duplicate")]
        public async Task<IActionResult> DuplicateActivity(int activity_id)
        {
            var ret = await AppService.Activity.DuplicateActivityAsync(MerchantId, activity_id);
            return OkResult(ret);
        }


    }
}